//
//  BZChooseView.m
//  QuickCure
//
//  Created by brice Mac on 16/9/13.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "BZChooseView.h"

@implementation BZChooseView

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    NSInteger radiu = [UIScreen mainScreen].bounds.size.width/375*40;
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, self.bounds.size.width/2-15, radiu)];
    self.lb_title = lab;
    lab.text = @"是否接受过治疗";
    lab.textColor = [UIColor lightGrayColor];
    [self addSubview:lab];
    
    UIButton *okBtn = [[UIButton alloc]init];
    [self addSubview:okBtn];
    [okBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [okBtn setTitle:@"接受过" forState:UIControlStateNormal];
    [okBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [okBtn setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
    [okBtn setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateSelected];
    
    [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(lab.mas_trailing);
        make.top.mas_equalTo(self).offset(5);
        make.bottom.mas_equalTo(self).offset(-5);
        make.width.mas_equalTo(@(2*radiu));
    }];
    [okBtn addTarget:self action:@selector(okBtnClick:) forControlEvents:UIControlEventTouchDown];
    
    UIButton *cancel = [[UIButton alloc]init];
    [self addSubview:cancel];
    [cancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [cancel setTitle:@"未接受过" forState:UIControlStateNormal];
    [cancel.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [cancel setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
    [cancel setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateSelected];
    
    [cancel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(okBtn.mas_trailing);
        make.top.mas_equalTo(self).offset(5);
        make.bottom.mas_equalTo(self).offset(-5);
        make.trailing.mas_equalTo(self);
    }];
    [cancel addTarget:self action:@selector(cancelBtnClick:) forControlEvents:UIControlEventTouchDown];
    
    
    self.backgroundColor = [UIColor whiteColor];
    
    return self;
}

- (void)okBtnClick:(UIButton *)btn {
    self.btn_select.selected = NO;
    btn.selected = YES;
    self.btn_select = btn;
    self.lb_title.text = btn.currentTitle;
    self.lb_title.textColor = [UIColor blackColor];
    if (self.block) {
        self.block(1);
    }
}

- (void)cancelBtnClick:(UIButton *)btn {
    self.btn_select.selected = NO;
    btn.selected = YES;
    self.btn_select = btn;
    self.lb_title.text = btn.currentTitle;
    self.lb_title.textColor = [UIColor blackColor];
    if (self.block) {
        self.block(0);
    }
}


@end
